// pages/comingrecord/comingrecord.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    slesson:"早自习",
    snumber:'',
    // myInfo:{
    //   snumber:''
    // },
    setTime: 0,
    weekday: ["星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期天"],
    hiddenmodalput: true,
    hiddenmodalputOne: true,
    hiddenmodalputTwo: true,
    hiddenmodalputThree: true,
    morstudy:"早自习",
    evenstudy:"晚自习",
    sleep:"寝室晚点名",
    activitysign:"活动签到",
    morningstu: "",
    eveningstu: "",
    dormitorystu:"",
    activitystu: "",
    number: 0,
    numberOne: 0,
    numberTwo: 0,
    numberThree: 0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var _this = this
    var UserInfo = app.globalData.UserInfo
    var grade = UserInfo.curGrade
    var classO = UserInfo.curClass
    // console.log(UserInfo)
    var now = new Date()
    var year = now.getFullYear()
    var month = now.getMonth() + 1
    var date = now.getDate()
    var day = now.getDay()
    var days = this.data.weekday[day - 1]
    var time = year + '-' + month + '-' + date + ' ' + days
    // console.log(time)
    _this.setData({
      setTime: time,
    })
    wx.request({
      url: 'https://nottoday.club/index.php/api/Student/getStudentByClass',
      data: {
        grade : grade,
        class : classO
      },
      header: {
        "Content-Type": "application/x-www-form-urlencoded",
        'cookie': wx.getStorageSync("sessionid")
      },
      method: 'POST',
      dataType: 'json',
      responseType: 'text',
      success: function (res) {
        // console.log(res.data)
        // console.log(res.data.data.length)
        _this.setData({
          snumber: res.data.data.length
          // myInfo: {snumber:res.data.data.length}
          // 将获取数据渲染到初始化界面
        })
      },
      fail: function (res) { },
      complete: function (res) { },
    })

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  /*
  自定义函数
  */

  //点击按钮痰喘指定的hiddenmodalput弹出框
  modalinput: function () {
    this.setData({
      hiddenmodalput: !this.data.hiddenmodalput,
    }) 
    var _this = this
    var UserInfo = app.globalData.UserInfo
    // var reqData = {
    //   grade: UserInfo.curGrade,
    //   class: UserInfo.curClass,
    //   type: 1
    // }
    // console.log(reqData)
    wx.request({
      url: 'https://nottoday.club/index.php/api/Attendance/getAttendanceByClass',
      data: {
        grade: UserInfo.curGrade ,
        class: UserInfo.curClass,
        type: 'morning'
      },
      header: {
        "Content-Type": "application/x-www-form-urlencoded",
        'cookie': wx.getStorageSync("sessionid")
      },
      method: 'POST',
      dataType: 'json',
      responseType: 'text',
      success: function (res) {
        // console.log(res)
        console.log(res.data)
        // console.log(res.data.data)
        if (res.data.data[0]){
          var name = res.data.data[0].stuname
          for (var i = 1; i < res.data.data.length; i++) {
            name = name + '，' + res.data.data[i].stuname
          }
          _this.setData({
            morningstu: name,
            number: res.data.data.length
            // 将获取数据渲染到初始化界面
          })
        }
      },
      fail: function (res) { },
      complete: function (res) { },
    })
  },

  //取消按钮
  cancel: function () {
    this.setData({
      hiddenmodalput: true
    });
  },

  //确认
  confirm: function () {
    this.setData({
      hiddenmodalput: true
    })
  },
 
//  晚自习
  modalinputOne: function () {
    this.setData({
      hiddenmodalputOne: !this.data.hiddenmodalputOne,
    })
    var _this = this
    var UserInfo = app.globalData.UserInfo
    wx.request({
      url: 'https://nottoday.club/index.php/api/Attendance/getAttendanceByClass',
      data: {
        grade: UserInfo.curGrade,
        class: UserInfo.curClass,
        type: 'evening'
      },
      header: {
        "Content-Type": "application/x-www-form-urlencoded",
        'cookie': wx.getStorageSync("sessionid")
      },
      method: 'POST',
      dataType: 'json',
      responseType: 'text',
      success: function (res) {
        if (res.data.data[0]) {
          var name = res.data.data[0].stuname
          for (var i = 1; i < res.data.data.length; i++) {
            name = name + '，' + res.data.data[i].stuname
          }
          _this.setData({
            eveningstu: name,
            numberOne: res.data.data.length
            // 将获取数据渲染到初始化界面
          })
        }
      },
      fail: function (res) { },
      complete: function (res) { },
    })
  },

  cancelOne: function () {
    this.setData({
      hiddenmodalputOne: true
    });
  },

  confirmOne: function () {
    this.setData({
      hiddenmodalputOne: true
    })
  },

  //  寝室
  modalinputTwo: function () {
    this.setData({
      hiddenmodalputTwo: !this.data.hiddenmodalputTwo,
    })
    var _this = this
    var UserInfo = app.globalData.UserInfo
    wx.request({
      url: 'https://nottoday.club/index.php/api/Attendance/getAttendanceByClass',
      data: {
        grade: UserInfo.curGrade,
        class: UserInfo.curClass,
        type: 'dormitory'
      },
      header: {
        "Content-Type": "application/x-www-form-urlencoded",
        'cookie': wx.getStorageSync("sessionid")
      },
      method: 'POST',
      dataType: 'json',
      responseType: 'text',
      success: function (res) {
        if (res.data.data[0]) {
          var name = res.data.data[0].stuname
          for (var i = 1; i < res.data.data.length; i++) {
            name = name + '，' + res.data.data[i].stuname
          }
          _this.setData({
            dormitorystu: name,
            numberTwo: res.data.data.length
            // 将获取数据渲染到初始化界面
          })
        }
      },
      fail: function (res) { },
      complete: function (res) { },
    })
  },

  cancelTwo: function () {
    this.setData({
      hiddenmodalputTwo: true
    });
  },

  confirmTwo: function () {
    this.setData({
      hiddenmodalputTwo: true
    })
  },

  // 活动
  modalinputThree: function () {
    this.setData({
      hiddenmodalputThree: !this.data.hiddenmodalputThree,
    })
    var _this = this
    var UserInfo = app.globalData.UserInfo
    wx.request({
      url: 'https://nottoday.club/index.php/api/Attendance/getAttendanceByClass',
      data: {
        grade: UserInfo.curGrade,
        class: UserInfo.curClass,
        type: 'activity'
      },
      header: {
        "Content-Type": "application/x-www-form-urlencoded",
        'cookie': wx.getStorageSync("sessionid")
      },
      method: 'POST',
      dataType: 'json',
      responseType: 'text',
      success: function (res) {
        if (res.data.data[0]) {
          var name = res.data.data[0].stuname
          for (var i = 1; i < res.data.data.length; i++) {
            name = name + '，' + res.data.data[i].stuname
          }
          _this.setData({
            activitystu: name,
            numberThree: res.data.data.length
            // 将获取数据渲染到初始化界面
          })
        }
      },
      fail: function (res) { },
      complete: function (res) { },
    })
  },

  cancelThree: function () {
    this.setData({
      hiddenmodalputThree: true
    });
  },

  confirmThree: function () {
    this.setData({
      hiddenmodalputThree: true
    })
  }


})
